package com.kdtech.analyse.video;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.StringUtils;
import com.kdtech.analyse.AnalyseNews;

/**
 * 南宁网络电视台
 * @author Administrator
 * abc
 */
public class NntvAnalyse implements AnalyseNews{
	
	public boolean isDetailPage(String url) {
		boolean bRet = false;
		String[] regex = {
				"http://www.nntv.cn/[a-z]*/[0-9]{4}-[0-9]{2}/[0-9]{2}/cms[0-9]*article.shtml",
				"http://www.nntv.cn/.*/[0-9]{4}-[0-9].*-[0-9].*/[0-9].*.shtml"
				};
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		NewsMeta video = new NewsMeta();
		if (urlMeta.getHtml() == null) {
		}
		String htmltxt = urlMeta.getHtml();
		String url = urlMeta.getUrl();
		if(!isDetailPage(url)){
		}
		video.setUrl(url);
		String title = null;
		String desc = null;
		Long date = null;
		String dateStr = null;
		Document doc = Jsoup.parse(htmltxt);
		title = doc.select("div.main >div.main_left >div.main_left_in >h1").text();

		if(StringUtils.isBlank(title)){
			title=doc.select("html body div.list_nav span.list_on a").text();
		}
		if(StringUtils.isBlank(title)){
			title=doc.select("html body div.main div.list_left div.content_left div.content_left_header h3").text();
		}
			desc = doc.select("#con_topic_txt2").text();
			if(desc.equals("收起")){
				desc="";
			}
			dateStr =doc.select("div.main >div.main_left >div.main_left_in >div.articleOpts").text();
			date = DateUtils.matchDate(dateStr);
			if(date==null){
				date=DateUtils.matchDate(url);
			}
			video.setTitle(StringUtils.trimSpace(title));
			video.setContent(desc);
			video.setDate(date);
			return video;
	}
	

	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}
	
}
